<!DOCTYPE html>
{% load static %}
<html lang="ru">

<head>
    {% if is_token %}
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Регистрация</title>
    <link rel="stylesheet" href="{% static 'css/registration/login.css' %}?v=1">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
    <link rel="shortcut icon" href="{% static 'img/global/icon.png' %}" type="image/x-icon">
    {% else %}
    <title>Нет токена</title>
    <link rel="stylesheet" href="{% static 'css/global/not_authorized.css' %}">
    <link rel="shortcut icon" href="{% static 'img/global/icon.png' %}" type="image/x-icon">
    {% endif %}
</head>

<body>
    {% if is_token %}
    <a href="{% url 'home' %}" class="logo"><img src="{% static 'img/global/long_logo.svg' %}" alt="Логотип лицея"></a>

    <form action="" method="post" class="form">
        <h1 class="title">Регистрация</h1>
        <div class="form-div">
            <div class="form-subdiv">
                <div class="input">
                    <label for="id_last_name">Фамилия:</label>
                    {{ user_form.last_name }}
                </div>
                <div class="input">
                    <label for="id_first_name">Имя:</label>
                    {{ user_form.first_name }}
                </div>
                <div class="input">
                    <label for="id_middle_name">Отчество:</label>
                    {{ user_form.middle_name }}
                </div>
                <div class="input input-group">
                    <label for="id_group">Группа:</label>
                    {{ user_form.group }}
                </div>
            </div>
            <div class="line"></div>
            <div class="form-subdiv">
                <div class="input">
                    <label for="id_username">Логин:</label>
                    {{ user_form.username }}
                </div>
                <div class="input">
                    <label for="id_email">Почта:</label>
                    {{ user_form.email }}
                </div>
                <div class="input">
                    <label for="id_password">Пароль:</label>
                    <div class="input-password">
                        {{ user_form.password }}
                        <button class="btn-eye" type="button" onclick="eye_view(this, 'id_password')"></button>
                    </div>
                </div>
                <div class="input">
                    <label for="id_password2">Повторите пароль:</label>
                    <div class="input-password">
                        {{ user_form.password2 }}
                        <button class="btn-eye" type="button" onclick="eye_view(this, 'id_password2')"></button>
                    </div>
                </div>
            </div>
        </div>
        {% csrf_token %}
        <input type="submit" class="btn btn-success" value="Создать аккаунт" name="register_submit">

    </form>
    {% if messages %}
    <ul class="errorlist">
        {% for message in messages %}
        <li>{{ message }}</li>
        {% endfor %}
    </ul>
    {% endif %}

    <script>
        let input = document.querySelectorAll('input');
        for (let i = 0; i < 8; i++) {
            input[i].setAttribute('required', 'true');
        }
        console.log(input);

    {% if token_role == "Учитель" %}
        let group = document.querySelector('.input-group');
        group.classList.add('input-hidden');
        document.getElementById('id_group').value = 0;
    {% endif %}

    function eye_view(btn, input_id) {
        let input = document.getElementById(input_id);
        
        if (btn.classList.contains('eye-show')) {
            input.setAttribute('type', 'password');
            btn.classList.remove('eye-show');
        } else {
            input.setAttribute('type', 'text');
            btn.classList.add('eye-show');
        }
    }
    </script>

    {% else %}
    <a href="{% url 'home' %}" class="logo"><img src="{% static 'img/global/long_logo.svg' %}" alt="Логотип лицея"></a>
    <div class="div-error">
        <p class="hi">Йоу, мэн, ты не можешь зарегаться без токена</p>
        <img src="{% static 'img/global/not_token.jpg' %}" alt="Еделев..." style="width: 60%; max-width: 700px;">
        <p class="advice-p">Иди введи токен, пока не засмеяли</p>
        <a href="{% url 'token_page' %}">Ввести токен</a>
    </div>
    {% endif %}
</body>

</html>